package com.biz.primus.ms.oms.trans;

import com.biz.primus.common.utils.Copier;
import com.biz.primus.model.oms.vo.OmsConsigneeVo;
import com.biz.primus.ms.base.service.IdService;
import com.biz.primus.ms.oms.dao.po.OmsConsignee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author yanweijin
 * @date 2017/10/31
 */
@Component
public class ConsigneeConverter {


	@Autowired
	private IdService idService;

	public OmsConsignee vo2po(OmsConsigneeVo vo, Long orderId) {
		OmsConsignee consignee = doForward(vo);
		consignee.setId(idService.getNextId());
		consignee.setOrderId(orderId);
		return consignee;
	}

	public OmsConsigneeVo po2vo(OmsConsignee po){
		return doBackward(po);
	}

	private OmsConsignee doForward(OmsConsigneeVo vo) {
		OmsConsignee consignee = new OmsConsignee();
		consignee.setAddress(vo.getAddress());
		consignee.setProvinceId(vo.getProvinceId());
		consignee.setDistrictId(vo.getDistrictId());
		consignee.setCityId(vo.getCityId());
		consignee.setLat(vo.getLat());
		consignee.setLat(vo.getLon());
		consignee.setMobile(vo.getConsigneeMobile());
		consignee.setName(vo.getConsigneeName());
		consignee.setOperator(vo.getOperator());
		consignee.setModifyRemark(vo.getModifyRemark());
		consignee.setPostcode(vo.getPostcode());
		consignee.setEmail(vo.getEmail());
		return consignee;
	}

	private OmsConsigneeVo doBackward(OmsConsignee po) {
		OmsConsigneeVo vo = new OmsConsigneeVo();
		Copier.from(po).to(vo);
		vo.setConsigneeMobile(po.getMobile());
		vo.setConsigneeName(po.getName());
		return vo;
	}



}
